package com.ssy.lingxi.order.controller.mobile;

import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.order.model.vo.basic.request.MobileDeliveryDateVO;
import com.ssy.lingxi.order.model.vo.basic.request.OrderLrcVO;
import com.ssy.lingxi.order.model.vo.basic.request.OrderSeparateVO;
import com.ssy.lingxi.order.model.vo.basic.response.OrderCompleteVO;
import com.ssy.lingxi.order.model.vo.basic.response.OrderDeliveryDateVO;
import com.ssy.lingxi.order.model.vo.basic.response.OrderLrcDetailVO;
import com.ssy.lingxi.order.model.vo.basic.response.PayResultDetailVO;
import com.ssy.lingxi.order.model.vo.buyer.request.BuyerMergePayVO;
import com.ssy.lingxi.order.model.vo.buyer.request.BuyerPayResultVO;
import com.ssy.lingxi.order.model.vo.buyer.request.BuyerPointsOrderVO;
import com.ssy.lingxi.order.model.vo.buyer.response.BuyerPayResultDetailVO;
import com.ssy.lingxi.order.model.vo.mobile.request.BuyerOrderVO;
import com.ssy.lingxi.order.model.vo.mobile.request.MobileBusinessOrderVO;
import com.ssy.lingxi.order.model.vo.mobile.response.MobileProcessDetailVO;
import com.ssy.lingxi.order.service.web.IOrderCreationService;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @menu App - 订单创建相关接口
 * @author 万宁
 * @version 2.0.0
 * @date 2021-09-22
 */
@RestController
@RequestMapping("/order/mobile/create")
public class MobileOrderCreationController {
    @Resource
    private IOrderCreationService orderCreationService;

    /**
     * APP-根据供应商会员信息和商城id获取预约时长和配置配送时间段
     * @param headers HttpHeaders信息
     * @param deliveryDateVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/find/delivery/date", method = RequestMethod.GET)
    public Wrapper<OrderDeliveryDateVO> findDeliveryDate(@RequestHeader HttpHeaders headers, @Valid MobileDeliveryDateVO deliveryDateVO) {
        return orderCreationService.findMobileDeliveryDate(headers, deliveryDateVO);
    }

    /**
     * “进货单” - 判断是否可以合并下单
     * @param headers HttpHeaders信息
     * @param separateVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/check", method = RequestMethod.POST)
    public Wrapper<Void> checkOrderMergeCondition(@RequestHeader HttpHeaders headers, @RequestBody @Valid OrderSeparateVO separateVO) {
        return orderCreationService.checkOrderMergeCondition(headers, separateVO);
    }

    /**
     * 企业商城、渠道商城首页 - 订单创建之前，查询支付方式和支付渠道信息
     * @param headers HttpHeader信息
     * @param separateVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/payment/find", method = RequestMethod.POST)
    public Wrapper<MobileProcessDetailVO> findOrderProcessPaymentSetting(@RequestHeader HttpHeaders headers, @RequestBody @Valid OrderSeparateVO separateVO) {
        return orderCreationService.findMobileProcessPaymentSetting(headers, separateVO);
    }

    /**
     * 企业商城、渠道商城首页 - 创建订单
     * @param headers HttpHeader信息
     * @param orderVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/buyer", method = RequestMethod.POST)
    public Wrapper<OrderCompleteVO> createMobileBuyerOrder(@RequestHeader HttpHeaders headers, @RequestBody @Valid BuyerOrderVO orderVO) {
        return orderCreationService.createMobileBuyerOrder(headers, orderVO);
    }

    /**
     * 创建拼团订单
     * @param headers HttpHeader信息
     * @param orderVO 接口参数
     * @return 创建结果
     */
    @RequestMapping(value = "/group", method = RequestMethod.POST)
    public Wrapper<OrderCompleteVO> createMobileGroupOrder(@RequestHeader HttpHeaders headers, @RequestBody @Valid BuyerOrderVO orderVO) {
        return orderCreationService.createMobileGroupOrder(headers, orderVO);
    }

    /**
     * 积分商城 - 创建积分订单
     * @param headers HttpHeader信息
     * @param orderVO 接口参数
     * @return 创建结果
     */
    @RequestMapping(value = "/points", method = RequestMethod.POST)
    public Wrapper<OrderCompleteVO> createMobilePointsOrder(@RequestHeader HttpHeaders headers, @RequestBody @Valid BuyerPointsOrderVO orderVO) {
        return orderCreationService.createMobilePointsOrder(headers, orderVO);
    }

    /**
     * 询价报价 - 创建B2B订单
     * @param headers HttpHeader信息
     * @param orderVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/b2b", method = RequestMethod.POST)
    public Wrapper<OrderCompleteVO> createMobileBusinessOrder(@RequestHeader HttpHeaders headers, @RequestBody @Valid MobileBusinessOrderVO orderVO) {
        return orderCreationService.createMobileBusinessOrder(headers, orderVO);
    }

    /**
     * 订单支付
     * @param headers HttpHeader信息
     * @param payVO 接口参数
     * @return 支付链接（在线支付）
     */
    @RequestMapping(value = "/buyer/pay", method = RequestMethod.POST)
    public Wrapper<PayResultDetailVO> orderPay(@RequestHeader HttpHeaders headers, @RequestBody @Valid BuyerMergePayVO payVO) {
        return orderCreationService.orderPay(headers, payVO);
    }

    /**
     * 查询支付结果
     * @param headers HttpHeader信息
     * @param resultVO 接口参数
     * @return 支付结果
     */
    @RequestMapping(value = "/buyer/pay/result", method = RequestMethod.GET)
    public Wrapper<BuyerPayResultDetailVO> findPayResult(@RequestHeader HttpHeaders headers, @Valid BuyerPayResultVO resultVO) {
        return orderCreationService.findPayResult(headers, resultVO);
    }

    /**
     * “进货单”-待结算订单-查询积分列表
     * @param headers HttpHeader信息
     * @param lrcVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/lrc/list", method = RequestMethod.POST)
    public Wrapper<List<OrderLrcDetailVO>> getLrcList(@RequestHeader HttpHeaders headers, @RequestBody @Valid OrderLrcVO lrcVO) {
        return orderCreationService.getLrcList(headers, lrcVO);
    }
}
